# -*- coding: UTF-8 -*-
import yun_mqtt
import utime as time
import yun_network
import state_led
from modem import sim
from modem import net

#==========================================================
#填入MQTT信息
AccessToken = "#######"
ProjectKey = "#######"
mqttaddr = "sh-1-mqtt.iot-api.com"
serverport = 1883
#==========================================================



def main():
    state_led.led_disp_thread()     #led指示灯
    ret = yun_network.connect_network() #联网
    print("ret:",ret)
    if ret == True:
        yun_mqtt.mqtt_connect(mqttaddr,AccessToken,ProjectKey,serverport)   #连接thingscloud平台
    else:
        print('network-connection failed')
    n= 0
    while True:
        n +=1
        if n >= 70:
            if yun_mqtt.get_mqtt_state:
                yun_mqtt.update()
            n = 0
        print("csq",net.getCsq())
        time.sleep(1)
    
if __name__ == '__main__':
    print("SIM卡状态：",sim.getStatus())
    main()
